//============================================================================
// Name        : VisusAnalytics.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
#include "vsconfig.h"
#include "VsForegroundDetector.h"
using namespace std;
#include <stdio.h>

int main() {

	VsConfig config;
	config.load((char*)"ABC.txt");

	VsForegroundDetector foreground(&config.params->foregroundConf);
	IplImage *imageColor = cvCreateImage(cvSize(320,240),IPL_DEPTH_8U,3);
	IplImage *imageGray = cvCreateImage(cvSize(320,240),IPL_DEPTH_8U,1);
	IplImage *imgCapture = NULL;
	CvCapture *capture = NULL;
	char esc=0;

	int t = time(NULL), fps=0;

	capture = cvCaptureFromCAM(0);
	if(!capture)
	{
		printf("Nao tem capture\n");
	}
	else
	{
		while(esc != 'q')
		{

			imgCapture = cvQueryFrame(capture);

			cvPyrDown(imgCapture,imageColor);
			cvCvtColor(imageColor,imageGray,CV_RGB2GRAY);
			foreground.process(imageGray);

			fps++;
			if(t != time(NULL))
			{
				printf("FPS: %d\n",fps);
				fps = 0;
				t = time(NULL);
			}

			cvShowImage("imageColor",imageColor);
			cvShowImage("ForeGround",foreground.foregroundImg);
			esc = cvWaitKey(5);
		}
	}

	cvReleaseImage(&imageColor);
	cvReleaseImage(&imageGray);
	cvReleaseCapture(&capture);

	return 0;
}
